/**
 * 苯甲酸广口瓶
 */
Guangkouping = Widget.extend({
	ctor:function(){
		this._super();
		this.init();
		this.setTag(TAG_GUANG_BOTTLE);
	},
	init:function(){
		var body = new Button(this, 10, TAG_GUANGKOUPING, "#guangkouping.png", this.callback);
		var lid = new Button(this, 12, TAG_GUANG_PINGSAI, "#guang_pingsai.png", this.callback);
		lid.setPosition(0,40);
		var spoon = new Button(this, 8, TAG_GUANG_GANGSHAO, "#spoon4.png", this.callback);
		spoon.setPosition(150,0);		
	},
	openLid:function(){
		var lid=this.getChildByTag(TAG_GUANG_PINGSAI);
		var ber = cc.bezierBy(1,[cc.p(50,70),cc.p(60,-70),cc.p(60,-75)]);
		var rot=cc.rotateTo(1, 180);
		var spw=cc.spawn(ber,rot);
		var rot1=cc.rotateTo(0, 0);
		var seq = cc.sequence(spw,rot1,cc.callFunc(function() {
			lid.setSpriteFrame("lid2.png");
			gg.flow.next();
		}, this));
		lid.runAction(seq);
	},
	closeLid:function(){
		var lid=this.getChildByTag(TAG_GUANG_PINGSAI);
		var ber = cc.bezierBy(1,[cc.p(-40,100),cc.p(-60,130),cc.p(-60,75)]);
		var rot=cc.rotateTo(1, -180);
		var spw=cc.spawn(ber,rot);
		var rot1=cc.rotateTo(0, 0);
		var seq = cc.sequence(spw,rot1,cc.callFunc(function() {
			lid.setSpriteFrame("lid.png");
		}, this),cc.callFunc(function() {
			gg.flow.next();
		}, this));
		lid.runAction(seq);
	},	
	callback:function(p){
		var action=gg.flow.flow.action;
		var func = cc.callFunc(this.actionDone, this);
		switch(p.getTag()){
		case TAG_GUANG_PINGSAI:
			if(action==ACTION_DO1){
				this.openLid();
			}else if(action==ACTION_DO2){
				this.closeLid();
			}
			break;
		case TAG_GUANG_GANGSHAO:
			var rot=cc.rotateTo(0.6, 160);
			var move=cc.moveTo(0.6, cc.p(0,90));
			var move2=cc.moveTo(0.6, cc.p(50,40));
			var fad=cc.fadeOut(0);
			var spa=cc.spawn(move,rot);
			var seq=cc.sequence(spa,move2,move,move2,cc.callFunc(function() {
				var ben=new cc.Sprite("#salt5.png");
				this.addChild(ben);
				ben.setPosition(cc.p(0,-20));
				ben.setScale(0.5);
				var min=this.getParent().getChildByTag(TAG_BIAOMIANMIN);
				var seq=cc.sequence(cc.callFunc(function() {
					min.setSpriteFrame("biaomianmin.png");
				}, this),cc.delayTime(0.5),cc.fadeOut(0))
				min.runAction(seq);
			}, this),fad,func);
			p.runAction(seq);
			break;
		case TAG_GUANGKOUPING:
			var tag=new cc.Sprite("#tag.png");
			tag.setScale(3);
			this.addChild(tag, 13);
			tag.setPosition(70,50);
			var move=cc.moveTo(3, cc.p(0,-5));
			var sca=cc.scaleTo(3, 1);
			var spa=cc.spawn(move,sca);
			var seq=cc.sequence(cc.callFunc(function() {
				var label = new cc.LabelTTF("苯甲酸",gg.fontName,12);
				label.setColor(cc.color(0,0,0));
				label.setPosition(15, 10);
				tag.addChild(label, 13);
			}, this),spa,cc.callFunc(function() {
				gg.flow.next();
			}, this),func);
			tag.runAction(seq);						
			break;
		}
	},
	actionDone:function(p){
		switch(p.getTag()){
		case TAG_PINGSAI:
			gg.flow.next();
			break;
		case TAG_GUANG_GANGSHAO:
			gg.flow.next();
			break;
		case TAG_GUANGKOUPING:
			gg.flow.next();
			break;
		}
	},
});